/**
 * 日期类
 * @author DF
 */

xue.date = xue.date || {};
/**
 * 返回日期的毫秒数
 */
xue.date.getStamp = function(dateStr){
	return Date.parse(dateStr.replace(/-/gi,"/"));
};

/**
 * 结束日期是否在开始日期之后
 */
xue.date.comparison = function(s,e){
	var _s = this.getStamp(s),
		_e = this.getStamp(e);
	return( _s == _e || _s < _e );
};

/**
 * 获取当前日期
 *	d:返回到日期
 	h:返回到小时
 	m:返回到分钟
 	s:返回到秒
 	mi:返回到毫秒
 */
xue.date.getToday = function(o){
		var _Date			= new Date()
			,_year			= _Date.getYear()			//获取当前年份(2位)
			,_fullYear		= _Date.getFullYear()    	//获取完整的年份(4位,1970-????)
			,_month			= _Date.getMonth()+1       	//获取当前月份(0-11,0代表1月)
			,_date			= _Date.getDate()        	//获取当前日(1-31)
			,_day			= _Date.getDay()         	//获取当前星期X(0-6,0代表星期天)
			,_time			= _Date.getTime()        	//获取当前时间(从1970.1.1开始的毫秒数)
			,_hours			= ' '+_Date.getHours()       	//获取当前小时数(0-23)
			,_minutes		= ':'+_Date.getMinutes()     	//获取当前分钟数(0-59)
			,_seconds		= ':'+_Date.getSeconds()     	//获取当前秒数(0-59)
			,_milliseconds	= ':'+_Date.getMilliseconds()   //获取当前毫秒数(0-999)
			,_dateString	= _Date.toLocaleDateString()//获取当前日期
			;    
		var _mytime=_Date.toLocaleTimeString();     	//获取当前时间
			_Date.toLocaleString( );        			//获取日期与时间
			
		var _today=_fullYear+'-'+_month+'-'+_date;
		var _type='';
		switch(o){
			case 'd':
				break;
			case 'h':
				_type = _hours;
				break;
			case 'm':
				_type = _hours + _minutes;
				break;
			case 's':
				_type = _hours + _minutes + _seconds;
				break;
			case 'mi':
				_type = _hours + _minutes + _seconds + _milliseconds;
				break;
			default:
				_type='';
				break;
		}
		return _today+_type;	
};

/**
 * 返回日期差值
 * s:
 * e:
 * t:时间类型，与getToday相同：日期、小时、分钟、秒、默认为天
 */
xue.date.difference = function(s,e,t){
	var _s1 = s, _s2 = e;
	_s1 = _s1.replace(/\-/gi, "\/"),		_s2 = _s2.replace(/\-/g, "\/"); 
	_s1 = new Date(_s1),				_s2 = new Date(_s2);
	console.log(_s2+'\n'+_s1);
	var _times= _s2.getTime() - _s1.getTime();
	var _i = 1;
	if(t){
		switch(t){
			case 'd':
				_i = 1000 * 60 * 60 * 24;
				break;
			case 'h':
				_i = 1000 * 60 * 60;
				break;
			case 'm':
				_i = 1000 * 60;
				break;
			case 's':
				_i = 1000;
				break;
			default:
				_i = 1;
				break;
		}	
	} 
	console.log('_i: '+_i);

	var _days = parseInt(_times / _i);
	return _days;
};

// 倒计时
xue.date.countDown = function(e){};


